﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
 <div class="layuimini-container">
     <div class="layuimini-main">
         <fieldset class="table-search-fieldset layui-hide" id="searchField">
             <div>
                 <form class="layui-form layui-form-pane" >
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label">停机类型:</label>
                             <div class="layui-input-inline">
                                 <select id="StopType" name="StopType" lay-search>
                                     <option value="2" selected>计划内停机</option>
                                     <option value="1">实际停机</option>
                                 </select>
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">设备:</label>
                             <div class="layui-input-inline">
                                 <select id="F_EqpId" name="F_EqpId" lay-filter="splitType" lay-search>
                                     <option value="" selected>请选择</option>
                                 </select>
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">查询时间段</label>
                             <div class="layui-input-inline">
                                 <input type="text" id="StartTime" name="StartTime" autocomplete="off" class="layui-input">
                             </div>
                             <div class="layui-input-inline">
                                 <input type="text" id="EndTime" name="EndTime" autocomplete="off" class="layui-input">
                             </div>
                             <div class="layui-input-inline">
                                 <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                             </div>
                         </div>
                     </div>
                 </form>
             </div>
         </fieldset>
         <script type="text/html" id="toolbarDemo">
             <div class="layui-btn-container" id="toolbar">
                 <button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                 <button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                 <button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                 <button id="NF-details" name="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
             </div>
         </script>
         <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a id="NF-edit" authorize class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
            <a id="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
            <a id="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal" lay-event="details"><i class="layui-icon">&#xe60b;</i></a>
        </script>
     
     
     
     </div>
 </div>
 <script>
     layui.use(['jquery', 'form','table','commonTable', 'common','optimizeSelectOption'], function () {
         var $ = layui.jquery,
             form = layui.form,
             laydate = layui.laydate,
             table = layui.table,commonTable = layui.commonTable
         common = layui.common;

         laydate.render({
             elem: '#StartTime'
             , trigger: 'click'
             , type: 'datetime'
             , format: 'yyyy/MM/dd HH:mm:ss',
             value: new Date((new Date()).getTime() - 24 * 60 * 60 * 1000*7)
         });

         laydate.render({
             elem: '#EndTime'
             , trigger: 'click'
             , type: 'datetime'
             , format: 'yyyy/MM/dd HH:mm:ss',
             value: new Date((new Date()).getTime() + 24 * 60 * 60 * 1000 * 7)
         });


         $(function () {
             initControl();
             form.render();
         });

         function initControl() {
             layui.$('#F_EqpId').bindSelect({
                 url: "/EquipmentManage/EqpPqcCheckItem/GetEqpListJson",
                 id: "F_Id",
                 text: "F_EqpName"
             });
         }


         //权限控制(js是值传递)
         currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
         toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
         commonTable.rendertable({
             elem: '#currentTableId',
             id: 'currentTableId',
             url: '/EquipmentManage/EqpStopRecord/GetGridJson',
             where: {
                 F_EqpId: $('#F_EqpId').val(),
                 StopType: $('#StopType').val(),
                 StartTime: $('#StartTime').val(),
                 EndTime:$('#EndTime').val()
             },
             cols: [[
                 //此处需修改
                 { type: "checkbox", width: 50 },
                 { field: 'F_EqpName', title: '设备', width: 130,sort: true,filter: true },
                 {
                     field: 'F_StopType', title: '停机类型', width: 120, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_StopType == 1) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>实际停机</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>计划内停机</span>";
                         }
                     }
                 },
                 {
                     field: 'F_PlanStopStartTime', title: '计划停机开始时间', width: 220, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_StopType == 1) {
                             return "<span>\\</span>";
                         }
                         else if (d.F_StopType == 2 && !!d.F_RepeatWeekday) {
                             return "每周" + d.F_RepeatWeekday +"的"+ d.F_PlanStopStartTime.split(" ")[1];
                         }
                         else {
                             return d.F_PlanStopStartTime;
                         }
                     }
                 },
                 {
                     field: 'F_PlanStopEndTime', title: '计划停机结束时间', width: 220, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_StopType == 1) {
                             return "<span>\\</span>";
                         }
                         else if (d.F_StopType == 2 && !!d.F_RepeatWeekday) {
                             return "每周" + d.F_RepeatWeekday+"的" + d.F_PlanStopEndTime.split(" ")[1];
                         }
                         else {
                             return d.F_PlanStopEndTime;
                         }
                     }
                 },
                 {
                     field: 'F_StopReasonType', title: '原因分类', width: 110, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_StopReasonType == 1) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>人</span>";
                         } 
                         if (d.F_StopReasonType == 2) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>机</span>";
                         } 
                         if (d.F_StopReasonType == 3) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>料</span>";
                         } 
                         if (d.F_StopReasonType == 4) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>法</span>";
                         } 
                         if (d.F_StopReasonType == 5) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>环</span>";
                         } 

                     }
                 },
                 { field: 'F_StopReason', title: '停机原因', width: 200,sort: true,filter: true },
                 { field: 'F_RealStopStartTime', title: '实际停机开始时间', width: 170,sort: true,filter: true },
                 { field: 'F_RealStopEndTime', title: '实际停机结束时间', width: 170,sort: true,filter: true },
                 { field: 'F_Solution', title: '解决措施', width: 110,sort: true,filter: true },
                 { field: 'F_Description', title: '备注', width: 100,sort: true,filter: true },
                { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center" }
             ]]
         });
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             var oDate1 = new Date(data.field.StartTime);
             var oDate2 = new Date(data.field.EndTime);
             if (oDate1 > oDate2) {
                 common.modalMsg("结束时间不能早于开始时间", "warning");
                 return false;
             }

             //执行搜索重载
             commonTable.reloadtable({
                 elem: 'currentTableId',
                 curr: 1,
                 where: {
                     F_EqpId: data.field.F_EqpId,
                     StartTime: data.field.StartTime,
                     EndTime: data.field.EndTime,
                     StopType: data.field.StopType,
                 }
             });
             return false;
         });
         wcLoading.close();
         //行点击事件监听，控制按钮显示
        var oneList = ["NF-edit", "NF-details"];//选择1条显示
        var morerList = ["NF-delete"];//选中1条以上显示
        commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", oneList, morerList);
         //toolbar监听事件
         table.on('toolbar(currentTableFilter)', function (obj) { 
             var data = table.checkStatus('currentTableId').data;
             var id = data.length > 0 ? data[0].F_Id : null;
             let stopType = data.length > 0 ? data[0].F_StopType:null;

             if (obj.event === 'add') {  // 监听添加操作
                 common.modalOpen({
                     title: "添加界面",
                     url: "/EquipmentManage/EqpStopRecord/AddForm",
                     width: "500px",
                     height: "1000px",
                 });
             } 
             else if (obj.event === 'delete') {
                if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i].F_Id);
                }
                 common.deleteForm({
                     url: "/EquipmentManage/EqpStopRecord/DeleteForm",
                     param: { keyValue: ids.join(',') },
                     success: function () {
                         common.reload('data-search-btn');
                   }
               });
           }
           else if (obj.event === 'edit') {
                if (data.length == 0) {
                   common.modalMsg("未选中数据", "warning");
                   return false;
               }
               common.modalOpen({
                  title: "编辑界面",
                   url: "/EquipmentManage/EqpStopRecord/Form?keyValue=" + id + "&stopType=" + stopType,
                   width: "500px",
                   height: "1000px",
               });
           }
           else if (obj.event === 'details') {
                if (data.length == 0) {
                   common.modalMsg("未选中数据", "warning");
                   return false;
               }
               common.modalOpen({
                  title: "查看界面",
                   url: "/EquipmentManage/EqpStopRecord/Details?keyValue=" + id + "&stopType=" + stopType,
                   width: "500px",
                   height: "1000px",
                  btn: []
               });
           }
           else if (obj.event === 'TABLE_SEARCH') {
                var _that = $("#searchField");
                if (_that.hasClass("layui-hide")) {
                   _that.removeClass('layui-hide');
                } else {
                   _that.addClass('layui-hide');
                }
           }
           return false;
       });
        //toolrow监听事件
        table.on('tool(currentTableFilter)', function (obj) {
            var id = obj.data.F_Id;
            let stopType = obj.data.F_StopType;
            if (obj.event === 'delete') {
                common.deleteForm({
                     url: "/EquipmentManage/EqpStopRecord/DeleteForm",
                     param: { keyValue: obj.data.F_Id },
                     success: function () {
                        obj.del();
                   }
               });
            }
            else if (obj.event === 'edit') {
               common.modalOpen({
                  title: "编辑界面",
                   url: "/EquipmentManage/EqpStopRecord/Form?keyValue=" + id + "&stopType=" + stopType,
                   width: "500px",
                   height: "1000px",
               });
            }
            else if (obj.event === 'details') {
               common.modalOpen({
                  title: "查看界面",
                   url: "/EquipmentManage/EqpStopRecord/Details?keyValue=" + id + "&stopType=" + stopType,
                   width: "500px",
                   height: "1000px",
                  btn: []
               });
            }
            return false;
        });
   });
</script>
